package Users.Cronerller;


import Users.Models.UserModels;

import java.util.Scanner;


public class UserControllers {
    UserModels newObject = new UserModels();
    Integer UserPwdError=3;
    Boolean isLogin = false;

    public void Into(){
        // todo 用户注册方法实现
        System.out.println("请输入用户名");
        newObject.setUserName(new Scanner(System.in).next());
        System.out.println("请输入密码");
        newObject.setPassWord(new Scanner(System.in).next());
        System.out.println("请输入积分");
        newObject.setIntegral(new Scanner(System.in).nextLong());
        newObject.setCardType();
        newObject.setUserCard((int)(1000+Math.random()*9000));
        System.out.println("录入成功,输入信息为"+ newObject.toString());
    }

    public void Login(){
        //todo 实现用户的登录功能
        for (int i =1;i<=UserPwdError;i++){
            System.out.println("请输入用户名");
            String UsernameInput = new Scanner(System.in).next();
            String GetUserName = newObject.getUserName();
            System.out.println("请输入密码");
            String UserPwdInput = new Scanner(System.in).next();
            String GetPassWord = newObject.getUserName();
            if (UsernameInput.equals(GetUserName) && UserPwdInput.equals(GetPassWord)){
                System.out.println("登录成功");
                this.isLogin=true;
                return;
            }else{
                System.out.println("登录失败,你还有"+(3-i)+"次机会");
            }
        }
        this.isLogin=false;
    }

    public Boolean isExit(){
        System.out.println("******是否继续******");
        return new Scanner(System.in).next().equals("y");
    }

    public void Number(){
        if (isLogin){
            System.out.println("请输入新密码");
            String Password = new Scanner(System.in).next();
            System.out.println("请再次输入新密码");
            String PasswordAnotherPassword = new Scanner(System.in).next();
            if (PasswordAnotherPassword.equals(Password)) {
                newObject.setPassWord(Password);
                System.out.println("密码修改成功" + newObject.toString());
            }else {
                System.out.println("两次输入的密码不同");
            }
        }else{
            System.out.println("你还未登录,请前往登录");
        }
    }

    public void Feedback(){
        if (isLogin){
            if ((newObject.getCardType().equals("钻石卡") && newObject.getIntegral()>1000) ||(newObject.getCardType().equals("普通卡") && newObject.getIntegral()>5000)) {
                newObject.setIntegral(newObject.getIntegral()+500L);
                System.out.println("你的积分现在是 "+newObject.getIntegral());
            }else {
                System.out.println("你未满足条件");
            }
        }else{
            System.out.println("你还未登录,请前往登录");
        }
    }

    public void PrintEnum() {
        System.out.println("******************");
        System.out.println("*****1**注册*******");
        System.out.println("*****2**登录*******");
        System.out.println("*****3**会员抽奖****");
        System.out.println("*****4**修改密码****");
        System.out.println("*****5**用户回馈****");
        System.out.println("*******************");
        System.out.println("******请选择菜单******");
    }

    public void Numbers(){
        int[] newArrays= new int[5];
        int UserCard = newObject.getUserCard();
        if (isLogin){
           for (int j =0 ;j<newArrays.length;j++){
               newArrays[j]=(int)(1000+Math.random()*9000);
           }
            for (int i:newArrays) {
                if (UserCard == i){
                    System.out.println("你中奖了");
                }
            }
            System.out.println("中奖名单如下");
            for (int j:newArrays) {
                System.out.println(j);
            }
            System.out.println("你未能中奖");
        }else{
            System.out.println("你还未登录");
        }
    }

}